
//  异步上传


function aa(obj) {

    var str = ''
    str += '<div class="M-img" style="width:100%;height: 100%;">'
    str += '<span class="M-title">请上传图片</span>'
    str += '</div>'
    str += '<form>'
    str += '<input type="file" name="file" class="M-file" style="display:none;">'
    str += '</form>'

    $(obj).append(str)           //添加隐藏文件标签

    $(obj).find('.M-img').click(function () {               //触发事件
        $(obj).find('.M-file').click()
    })
    $(obj).find('.M-file').change(function () {              //选中图片事件

        var formData = new FormData($(obj).find('form')[0]);           //转换为js对象
        $.ajax({
            url: "/upload",
            type: 'POST',
            data: formData,                                         //向后台传图片
            async: false,
            cache: false,
            contentType: false,
            processData: false,
            success: function (data) {
                if (data.ok == 1) {
                    $(obj).find('.M-file').val('')                   //情况选项
                    $(obj).find('.M-img').css({
                        "background-image": "url('/img/" + data.path + "')"
                    })
                    $(obj).find('.M-title').css({
                        "display":"none"
                    })
                } else {

                }
            },
            error: function (returndata) {
                alert(returndata);
            }
        });
    })


}